<script setup lang="ts">
import defaultImg from '@/assets/default.png'
import { ref, watch } from 'vue'
import { useSettingStore } from '@/stores'
const settingStore = useSettingStore()
// 成员列表的元素
const member_list_group = ref<HTMLElement>()
// 成员列表的宽度
const groupWidth = ref<string>('20%')
// video标签实例，播放本人的视频
const localVideo = ref<HTMLVideoElement>()

interface StreamItem {
  account: string
  avatar: string
  stream: MediaStream | null
}
const { remoteStream, localStream, account } = defineProps<{
  remoteStream: StreamItem[]
  localStream: MediaStream | null
  account: string
  avatar: string
}>()
// 成员列表变化
watch(
  () => settingStore.settingMeeting.groupStatus,
  newVal => {
    if (newVal) {
      groupWidth.value = '20%'
    } else {
      groupWidth.value = '0%'
    }
  }
)
</script>
<template>
  <div class="video_player_area">
    <div class="member-list-right">
      <div class="video_area">
        <img :src="avatar ? avatar : defaultImg" v-if="localStream == null" />
        <video
          v-else
          ref="localVideo"
          class="video"
          :srcObject="localStream"
          muted
          autoplay
        ></video>
        <span class="video_tip">{{ account }}</span>
      </div>
      <div
        class="video_group"
        ref="member_list_group"
        :style="{ width: groupWidth }"
      >
        <div
          class="video_item"
          v-for="item in remoteStream"
          :key="item.account"
        >
          <img
            :src="item.avatar ? item.avatar : defaultImg"
            alt=""
            v-if="item.stream === null"
          />
          <video
            class="video"
            id="remoteVideo"
            :srcObject="item.stream"
            :class="item.account"
            muted
            autoplay
            v-else
          ></video>
          <div class="video_tip">{{ item.account }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.video_player_area {
  height: 85%;
  .member-list-right {
    width: 100%;
    height: 100%;
    display: flex;
    .video_area {
      position: relative;
      flex: 1;
      background-color: rgb(45, 48, 51);
      video {
        position: absolute;
        top: 50%;
        left: 0;
        width: 100%;
        height: 100%;
        transform: translateY(-50%);
        // object-fit: fill;
      }
      img {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 40%;
        height: 50%;
        transform: translate(-50%, -50%);
        background-size: cover;
      }
      .video_tip {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100px;
        height: 30px;
        text-align: center;
        line-height: 30px;
        border-top-right-radius: 20px;
        background-color: rgba(255, 255, 255, 0.2);
        font-weight: 500;
        font-size: 18px;
        color: #fff;
      }
    }
    .video_group {
      position: relative;
      overflow-y: auto;
      scrollbar-width: none; /* 取消滚动条宽度 */
      scrollbar-color: auto; /* 取消滚动条颜色 */
      width: 20%;
      transition: all 0.5s;
      height: 100%;
      background: linear-gradient(to right, rgb(71, 71, 71) 20%, black);
      padding-top: 20px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      &::-webkit-scrollbar {
        display: none;
      }
      .video_item {
        position: relative;
        height: 18%;
        width: 90%;
        margin: 10px;
        video {
          width: 100%;
          height: 100%;
          object-fit: fill;
        }
        img {
          position: absolute;
          width: 50%;
          height: 90%;
          background-size: cover;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
        }
        .video_tip {
          position: absolute;
          left: 0;
          bottom: 0;
          width: 70px;
          height: 30px;
          text-align: center;
          line-height: 30px;
          border-top-right-radius: 20px;
          background-color: rgba(0, 0, 0, 0.3);
          font-weight: 500;
          font-size: 18px;
          color: #fff;
        }
      }
    }
  }
}
</style>
